// 只出现一次的数字3

package Leetcode;

class Solution_260 {
    public int[] singleNumber(int[] nums) {
        int xorSum = 0;
        for (int num : nums)
            xorSum ^= num;

        int lsb = xorSum == Integer.MAX_VALUE ? xorSum : xorSum & (-xorSum);
        int result1 = 0;
        int result2 = 0;
        for (int num : nums) {
            if ((num & lsb) == 0)
                result1 ^= num;
            else
                result2 ^= num;
        }
        return new int[] { result1, result2 };
    }
}